/*    */ package com.yc.filters;
/*    */ 
/*    */ import java.io.PrintStream;
/*    */ import javax.servlet.Filter;
/*    */ import javax.servlet.FilterChain;
/*    */ import javax.servlet.FilterConfig;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.ServletRequest;
/*    */ import javax.servlet.ServletResponse;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import javax.servlet.http.HttpSession;
/*    */ 
/*    */ public class LogOrNot
/*    */   implements Filter
/*    */ {
/*    */   private FilterConfig config;
/*    */   private String logon_page;
/*    */   private String home_page;
/*    */ 
/*    */   public void destroy()
/*    */   {
/* 19 */     this.config = null;
/*    */   }
/*    */ 
/*    */   public void init(FilterConfig filterconfig)
/*    */     throws ServletException
/*    */   {
/* 25 */     this.config = filterconfig;
/* 26 */     this.logon_page = filterconfig.getInitParameter("LOGON_URI");
/* 27 */     this.home_page = filterconfig.getInitParameter("HOME_URI");
/* 28 */     System.out.println(this.home_page);
/* 29 */     if ((this.logon_page == null) || (this.home_page == null))
/* 30 */       throw new ServletException("没有找到登录页面或主页");
/*    */   }
/*    */ 
/*    */   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
/*    */   {
/* 36 */     HttpServletRequest req = (HttpServletRequest)request;
/* 37 */     HttpServletResponse rpo = (HttpServletResponse)response;
/* 38 */     HttpSession session = req.getSession();
/*    */     try
/*    */     {
/* 41 */       req.setCharacterEncoding("utf-8");
/*    */     } catch (Exception e1) {
/* 43 */       e1.printStackTrace();
/*    */     }
/* 45 */     String userId = (String)session.getAttribute("stxtUName");
/* 46 */     Boolean objIsLogin = (Boolean)session.getAttribute("IS_LOGIN");
/* 47 */     String request_uri = req.getRequestURI();
/* 48 */     String ctxPath = req.getContextPath();
/* 49 */     String uri = request_uri.substring(ctxPath.length());
/* 50 */     System.out.println("request_uri = " + request_uri);
/*    */     try
/*    */     {
/* 53 */       if (request_uri.indexOf("serialcode.jsp") != -1)
/*    */       {
/* 57 */         chain.doFilter(request, response);
/*    */       } else {
/* 59 */         if ((request_uri.indexOf("login.jsp") == -1) && ((objIsLogin == null) || (objIsLogin.equals(Boolean.FALSE)))) {
/* 60 */           rpo.sendRedirect(this.home_page + this.logon_page);
/* 61 */           System.out.println(this.home_page + this.logon_page);
/* 62 */           return;
/*    */         }
/*    */ 
/* 66 */         chain.doFilter(request, response);
/*    */       }
/*    */     } catch (Exception e) {
/* 69 */       e.printStackTrace();
/*    */     }
/*    */   }
/*    */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     com.yc.filters.LogOrNot
 * JD-Core Version:    0.6.2
 */